package com.zhuge_new.Adapter;

import android.arch.lifecycle.ViewModelProvider;
import android.content.Context;
import android.net.ConnectivityManager;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhuge_new.Activity.CheckActivity;
import com.zhuge_new.R;
import com.zhuge_new.bean.CheckBean;
import com.zhuge_new.bean.ListDetailsBean;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.CRC32;

/**
 * Created by lenovo on 2018-09-18.
 */

public class CheckAdapter extends BaseQuickAdapter<ListDetailsBean.PayrecordsBean, BaseViewHolder> {

    private Context context;
    private ListDetailsBean listDetailsBean;
    private String creditcard;
    private ArrayList list = new ArrayList();

    public CheckAdapter(Context context, ListDetailsBean listDetailsBean, String creditcard) {
        super(R.layout.item_check, listDetailsBean.getPayrecords());
        this.context = context;
        this.listDetailsBean = listDetailsBean;
        this.creditcard = creditcard;
    }

    @Override
    public int getItemCount() {
        if (listDetailsBean.getPayrecords()==null) {
            return 0+getHeaderLayoutCount();
        } else {
            for (int i = 0; i < listDetailsBean.getPayrecords().size(); i++) {
                if (listDetailsBean.getPayrecords().get(i).getCardNo().equals(creditcard)) {
                    list.add(listDetailsBean.getPayrecords().get(i).getCardNo());
                }
            }
            return list == null ? 0 : list.size() + getHeaderLayoutCount();
        }
    }

    @Override
    protected void convert(BaseViewHolder helper, ListDetailsBean.PayrecordsBean item) {
        String cred = item.getCardNo();
        if (creditcard.equals(cred)) {
            helper.setText(R.id.check_item_tail, "尾号(" + cred.substring(creditcard.length() - 4, creditcard.length()) + ")");
            helper.setText(R.id.check_item_pattern, item.getPayType());
            helper.setText(R.id.check_item_rate, "[" + item.getRate() + "]");
            helper.setText(R.id.check_item_data, item.getPayTime().substring(5, 16));
            String paytype = item.getPayType();
            ImageView check_item_logo = helper.getView(R.id.check_item_logo);
            TextView check_item_state = helper.getView(R.id.check_item_state);
            if (paytype.equals("智能还款")) {
                check_item_logo.setImageResource(R.mipmap.shoukuanlogo);
                helper.setText(R.id.check_item_money, "+" + item.getPaySum());
            } else if (paytype.equals("收款")) {
                check_item_logo.setImageResource(R.mipmap.shoukuanlogo);
                helper.setText(R.id.check_item_money, "+" + item.getPaySum());
            } else {
                check_item_logo.setImageResource(R.mipmap.huankuanlogo);
                helper.setText(R.id.check_item_money, "-" + item.getPaySum());
            }
            String status = item.getStatus();
            if (status.equals("1")) {
                check_item_state.setText("交易成功");
            } else if (status.equals("0")) {
                check_item_state.setText("交易失败");
            } else {
                check_item_state.setText("交易中");
            }
            helper.addOnClickListener(R.id.check_entry_ety);
        }

    }
}
